#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <elf.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(int argc,char **argv)
{
  int fd1,fd2;

  int i; 

  void *file1,*file2;

  fd1 = open("boot.bin",O_RDONLY);
  fd2 = open("boot.img",O_RDWR);


  if(fd1 ==  0)  
    {
      printf("Open File Error!!!");
      exit(1);
    }

  if(fd2 ==  0)  
    {
      printf("Open File Error!!!");
      exit(1);
    }


  file1 = mmap(NULL
               ,512
               ,PROT_READ
               ,MAP_SHARED
               ,fd1
               ,0);

  file2 = mmap(NULL
               ,512
               ,PROT_WRITE
               ,MAP_SHARED
               ,fd2
               ,0);

  if(file1 < 0 )  
    {
      printf("map fail!!!!");
      exit(1);
    }

  if(file2 < 0 )  
    {
      printf("map fail!!!!");
      exit(1);
    }

  char *p1 = (char *)file1;
  char *p2 = (char *)file2;

  for(i = 0;i<512;i++)
    {
      *p2 = *p1;
      p1++;
      p2++;
    }

  munmap(file1,512);
  munmap(file2,512);


  return 0;
}
